package com.ls.pool;

import java.util.concurrent.*;

public class ThreadPoolDemo2 {
    public static void main(String[] args) {
        ExecutorService threadPool = new ThreadPoolExecutor(
                2,6,2L, TimeUnit.SECONDS
                ,new ArrayBlockingQueue<Runnable>(3), Executors.defaultThreadFactory()
        ,new ThreadPoolExecutor.AbortPolicy());

        try {
            for (int i = 1; i <= 20; i++) {
                threadPool.execute(() -> {
                    System.out.println(Thread.currentThread().getName());
                });
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            threadPool.shutdown();
        }

    }
}
